package com.mbc.controller;


import com.github.pagehelper.PageInfo;
import com.mbc.comment.Result;
import com.mbc.pojo.MbcFans;
import com.mbc.service.FansService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 粉丝表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-08
 */
@RestController
@RequestMapping("/fans")
@Api(tags = "粉丝接口")
@CrossOrigin
public class FansController {

    @Autowired
    private FansService fansService;


    /**
     * 分页查询粉丝列表
     * 2
     *
     * @param userId 用户 ID
     * @param page   页
     * @param size   大小
     * @return {@link Result}<{@link List}<{@link MbcFans}>>
     */
    @GetMapping("/{userId}")
    @ApiOperation("分页查询粉丝列表")
    public Result<PageInfo<MbcFans>> listFollowers(@PathVariable String userId, @RequestParam(defaultValue = "1") Integer page,
                                                   @RequestParam(defaultValue = "10") Integer size) {
        PageInfo<MbcFans> list = fansService.getAllByUserId(userId, page, size);
        return Result.success(list);
    }

    /**
     * 分页新增粉丝列表
     *
     * @param userId 用户 ID
     * @param page   页
     * @param size   大小
     * @return {@link Result}<{@link List}<{@link MbcFans}>>
     */
    @GetMapping("/addfans/{userId}")
    @ApiOperation("分页查询新增粉丝列表")
    public Result<PageInfo<MbcFans>> addFansList(@PathVariable String userId, @RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer size) {
        PageInfo<MbcFans> list = fansService.getAddFansList(userId, page, size);
        return Result.success(list);
    }

    /**
     * 删除粉丝取消关注
     *
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/delete/{fansId}")
    @ApiOperation("删除粉丝")
    public Result<Boolean> deleteFansUnfollow(@PathVariable String fansId) {
        return Result.success(fansService.deleteFansUnfollow(fansId));
    }

    /**
     * 新增粉丝
     *
     * @param fansId 粉丝 ID
     * @param userId 用户 ID
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/{userId}/{fansId}")
    @ApiOperation("新增粉丝")
    public Result<Boolean> insertFans(@PathVariable String fansId, @PathVariable String userId) {
        return Result.success(fansService.insertFans(fansId, userId));
    }
}
